import useMain from "@/stores/useMain.js";
import { mapState } from 'pinia';
import { Util,RxIconShow } from '@lowcode/jpaas-base-lib'
export default {
    components:{
        RxIconShow
    },
    computed:{
        ...mapState(useMain,['menus','appKey']),
        lang(){
            return window.localStorage.getItem('language') || 'zh-CN'
        }
    },
    data(){
        return {
            load:null,
            menuKey: '',
            appId: '',
            menu:[],
            activeKey:''
        }
    },
    methods:{
        getTabIcon(icon){
            let fn = new Function(`return ${icon}`)()
            return fn.icon ;
        },
        getName(name){
            if(Util.getObjType(name) === 'object'){
                return name[this.lang]
            }else if (name.includes("{") && name.includes("}")){
                let fn = new Function(`return ${name}`)();
                return fn[this.lang]
            }
            return name ;
        },
        init(){
            let {menuKey,appId} = this.$route.query ;
            this.appId = appId ;
            this.menuKey = menuKey ;
            let curMenu = this.menus.find(item=>item.menuKey === menuKey);
            if(curMenu && curMenu.children){
                this.menu = curMenu.children ;
                this.activeKey = this.menu[0].menuKey;
            }
        }
    },
    created(){
        this.init()
        this.load = this.$watch(()=>this.$route,()=>{
            this.init()
        },{deep:true})
    },
    beforeUnmount(){
        this.load()
        this.load = null ;
    }
}
